package com.dushiguang.findhoney.BmobDB;

import android.content.Context;
import android.location.Location;
import android.util.Log;

import com.dushiguang.findhoney.Bean.HoneyInfo;
import com.dushiguang.findhoney.Key.Keys;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.UpdateListener;

/**
 * Created by ex-dushiguang201 on 2015-11-02.
 */
public class BmobMethod {

    private BmobFindListener mBmobFindListener;
    private Context context;

    public BmobMethod () {
    }

    public void initBmob(Context context) {
        this.context = context;
        Bmob.initialize(context, Keys.BmobKey);
    }

    /**
     * 查找Bmob数据
     */
    public void FindBmobDb(String loginName,String loginPwd){
        BmobQuery<HoneyInfo> query = new BmobQuery<HoneyInfo>();
        query.addWhereEqualTo("honeyLoginName", loginName);

        mBmobFindListener = new BmobFindListener(loginPwd,context);
        query.findObjects(context, mBmobFindListener);
    }

    /**
     *
     */

    public void UpdateBmobDb(Context context, Location location, String ObjectId) {
        HoneyInfo honeyInfo = new HoneyInfo();
        honeyInfo.setHoneyLongitude(Double.toString(location.getLongitude()));//经度
        honeyInfo.setHoneyLatitude(Double.toString(location.getLatitude()));//纬度
        honeyInfo.update(context, ObjectId, new UpdateListener() {
            @Override
            public void onSuccess() {
                Log.e("dushiguang", "更新成功：");
            }

            @Override
            public void onFailure(int i, String s) {
                Log.e("dushiguang","更新失败：" + s);
            }
        });
    }
}
